import { defineStore } from "pinia";

const mainStore = defineStore("main", {
   state: (): MainStoreState => ({
      token: "",
      userInfo: {
         account: "",
         phone: "",
         role_id: ""
      },
      router: [],
      nowPath: "",
      nowLabel: ""
   }),
   getters: {},
   actions: {
      // 设置 state
      setStoreItem<T extends MainStoreStateItem>(key: T, value: MainStoreState[T]) {
         this.$state[key] = value;
      },
      /** 设置多个 state */
      setStoreItems(param: Partial<MainStoreState>) {
         const that = this;
         Object.keys(param).forEach(key => {
            that.$state[key] = param[key];
         });
      }
   },
   persist: {
      storage: localStorage
   }
});

export default mainStore;
